<?php

namespace Common\Model;

/**
 * 订单基本信息修改记录表
 * @modify trainyao 2016-01-05 创建
 * @index orderrecord_id (`orderrecord_id`);
 */
Class OrderInfoRecordModel extends \Common\Model\BaseModel {

    protected $trueTableName = 'tb_order_info_record';

    public function _before_insert(&$data, $options) {
        // parent::_before_insert($data, $options);
    }

    /**
     * 添加信息
     * @modity trainyao 2016-01-15 修改为值可传空
     * @modify wenhui 2017-05-04 增加区号
     * @param integer $orderRecordId  订单记录ID
     * @param inteegr $hotelchannelId 客栈渠道ID
     * @param string $remark 备注
     * @param string $mobile 手机号
     * @param string $name 入住姓名
     * @param string $identity 身份证
     * @param integer $hotelchannelBefore  修改前渠道
     * @param string $remarkBefore  备注修改前
     * @param string $mobileBefore 手机号修改前
     * @param string $nameBefore 入住姓名修改前
     * @param string $identityBefore
     * @param string $areaCode
     * @return type
     */
    public function addInfo($orderRecordId, $hotelchannelId, $remark, $mobile, $name, $identity, $hotelchannelBefore = 0, $remarkBefore = '', $mobileBefore = '', $nameBefore = '', $identityBefore = '', $areaCode = '86', $areaCodeBefore = '86') {
        $options = array(
            'orderrecord_id' => $orderRecordId,
        );
        if (!empty($hotelchannelId)) {
            $options['hotelchannel_id'] = $hotelchannelId;
        }
        if (!empty($hotelchannelBefore)) {
            $options['hotelchannel_before'] = $hotelchannelBefore;
        }

        if (!empty($remark)) {
            $options['remark'] = $remark;
        }
        if (!empty($remarkBefore)) {
            $options['remark_before'] = $remarkBefore;
        }

        if (!empty($identity)) {
            $options['identity'] = $identity;
        }
        if (!empty($identityBefore)) {
            $options['identity_before'] = $identityBefore;
        }

        if (!empty($mobile)) {
            $options['mobile'] = $mobile;
        }
        if (!empty($mobileBefore)) {
            $options['mobile_before'] = $mobileBefore;
        }

        if (!empty($name)) {
            $options['name'] = $name;
        }
        if (!empty($nameBefore)) {
            $options['name_before'] = $nameBefore;
        }
        if (!empty($areaCode)) {
            $options['areacode'] = $areaCode;
        }
        if (!empty($areaCodeBefore)) {
            $options['areacode_before'] = $areaCodeBefore;
        }

        return $this->add($options);
    }

    /**
     * 根据父订单修改记录取数据
     * @modify trainyao 2016-01-05     创建
     * @param  mixin   $orderRecordId 父订单修改记录id(s)
     * @return array                  修改记录数组
     */
    public function getInfoByOrderRecord($orderRecordId) {
        $option = array();
        if (is_array($orderRecordId)) {
            $orderRecordId = implode(',', $orderRecordId);
        }

        if (strpos($orderRecordId, ',') !== false) {
            $option['orderrecord_id'] = array('in', $orderRecordId);
        } else {
            $option['orderrecord_id'] = $orderRecordId;
        }
        $data = $this->where($option)->select();

        return empty($data) ? array() : $data;
    }

}
